package com.joeyee.echartsgenerator.controller;

import com.joeyee.echartsgenerator.echarts.bar.BarData;
import com.joeyee.echartsgenerator.echarts.line.LineData;
import com.joeyee.echartsgenerator.echarts.map.MapData;
import com.joeyee.echartsgenerator.echarts.wordcloud.WordCloudData;
import com.joeyee.echartsgenerator.enums.EchartsType;
import com.joeyee.echartsgenerator.service.EchartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;


@Api(value = "生成Echarts图表API接口", tags = "Echarts图表")
@RequestMapping("/echarts")
@RestController
public class EchartsController {

    @Autowired
    private EchartService echartService;

    @ApiOperation(value = "生成柱状图")
    @PostMapping(value = "/bar/{type}", produces = {MediaType.IMAGE_GIF_VALUE, MediaType.IMAGE_JPEG_VALUE,
            MediaType.IMAGE_PNG_VALUE})
    public byte[] createBar(@PathVariable EchartsType type, @RequestBody BarData barData){
        return echartService.buildEchart(type, barData);
    }

    @ApiOperation(value = "生成折线图")
    @PostMapping(value = "/line/{type}", produces = {MediaType.IMAGE_GIF_VALUE, MediaType.IMAGE_JPEG_VALUE,
            MediaType.IMAGE_PNG_VALUE})
    public byte[] createLine(@PathVariable EchartsType type, @RequestBody LineData lineData){
        return echartService.buildEchart(type, lineData);
    }

    @ApiOperation(value = "生成地图")
    @PostMapping(value = "/map/{type}", produces = {MediaType.IMAGE_GIF_VALUE, MediaType.IMAGE_JPEG_VALUE,
            MediaType.IMAGE_PNG_VALUE})
    public byte[] createMap(@PathVariable EchartsType type, @RequestBody MapData mapData){
        return echartService.buildEchart(type, mapData);
    }

    @ApiOperation(value = "生成云词")
    @PostMapping(value = "/wordcloud/{type}", produces = {MediaType.IMAGE_GIF_VALUE, MediaType.IMAGE_JPEG_VALUE,
            MediaType.IMAGE_PNG_VALUE})
    public byte[] createWordCloud(@PathVariable EchartsType type, @RequestBody WordCloudData wordCloudData){
        return echartService.buildEchart(type, wordCloudData);
    }
}
